Skip to content

feat(audience): bootstrap wiring, GA/Meta IDs, unload fix#2831

Merged
bkbooth merged 9 commits into
mainfrom
SDK-50-pixel-bootstrap
Apr 8, 2026
Merged

feat(audience): bootstrap wiring, GA/Meta IDs, unload fix#2831
bkbooth merged 9 commits into
mainfrom
SDK-50-pixel-bootstrap

Conversation

@bkbooth
Copy link
Copy Markdown
Contributor

@bkbooth bkbooth commented Apr 7, 2026

Summary

Completes the end-to-end pixel by wiring the command-queue loader to the Pixel class and adding third-party identity signals:

  • Bootstrap wiring (bootstrap.ts): Maps command names (init, page, identify, consent) to Pixel methods, installs createLoader() on window.__imtbl, replays any commands the snippet queued before the script loaded
  • Dedicated IIFE entry (iife.ts): CDN bundle only imports the bootstrap side-effect — excludes snippet generator and createLoader export (~500 bytes smaller)
  • GA / Meta cookie reads: Reads _ga (GA Client ID), _fbc (Meta click ID), _fbp (Meta browser ID) cookies and includes them in page view properties when present
  • Unload ordering fix: Registers session_end listeners before queue.start() so that on page unload, session_end is enqueued before the queue's flushUnload() fires (DOM listeners fire in registration order)

Bundle: 8.92 KB raw / ~3.4 KB gzipped (well under 10 KB budget)

Test plan

  • pnpm --filter @imtbl/audience-core test — 87/87 passing (11 suites)
  • pnpm --filter @imtbl/pixel test — 33/33 passing (4 suites)
  • pnpm --filter @imtbl/pixel build — IIFE bundle produced (8.92 KB)
  • pnpm --filter @imtbl/pixel lint — clean
  • pnpm --filter @imtbl/pixel typecheck — clean
  • CI passes

🤖 Generated with Claude Code

bkbooth and others added 8 commits April 7, 2026 13:13
…r, and snippet

Add the pixel package scaffold and three self-contained modules that have
no dependency on PR #2824. The package builds to a single IIFE bundle
(dist/imtbl.js) targeting <10KB gzipped (currently 823 bytes).

Modules:
- attribution: UTM params, ad click IDs, referrer, landing page (session-cached)
- loader: command-queue pattern (window.__imtbl) with pre-load replay
- snippet: embeddable <script> tag generator for studio integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… reference

Add dclid (Google DV360) and li_fat_id (LinkedIn) to match the
Tracking Pixel Event Reference doc. Also add referral_code parsing
and touchpoint_type derivation (set to 'click' when UTMs or click
IDs are present).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ion cookie

Wire the pixel to audience-core now that PR #2824 has merged:

- Consent state machine: three-level (none/anonymous/full), DNT/GPC detection,
  queue purge on downgrade to none, userId strip on downgrade to anonymous,
  fire-and-forget PUT to /v1/audience/tracking-consent
- Session cookie: _imtbl_sid with 30-min rolling expiry
- Pixel class: init creates MessageQueue with storagePrefix isolation,
  auto-fires PageMessage with attribution context, supports identify at
  full consent, setConsent, and destroy
- Build config: resolves audience-core from source via tsup alias for
  tree-shaken self-contained IIFE bundle (8.04 KB raw / 3.2 KB gzipped)
- Metrics stub: no-op stubs so the pixel bundle doesn't ship internal telemetry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add session lifecycle tracking to the Pixel class:
- Fire session_start track event on new session creation
- Fire session_end track event on pagehide/visibilitychange with duration
- Refactor session module to return SessionResult with isNew flag
- Fix test listener leaking by cleaning up pixel instances in afterEach

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move session management, attribution tracking, and consent state machine
from @imtbl/pixel into @imtbl/audience-core so the web SDK can share them.

- session.ts: use SESSION_COOKIE from core config instead of duplicating
- attribution.ts: UTM params, click IDs, referrer, sessionStorage caching
- consent.ts: three-level state machine with DNT/GPC, queue purge/transform
- Remove pixel re-exports of core modules (no backwards compat needed yet)
- Add SESSION_MAX_AGE constant to core config
- Pixel now imports everything from @imtbl/audience-core

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Read version from package.json in tsup.config.ts and inject it via
esbuild define as PIXEL_VERSION_INJECTED. This stamps every event
payload with the correct libraryVersion automatically — no manual
bumping needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ering

Bootstrap wiring:
- Add bootstrap.ts that maps command names to Pixel methods (init,
  page, identify, consent) and calls createLoader() to install on
  window.__imtbl with command replay
- Add iife.ts as dedicated CDN entry point (excludes snippet generator
  and createLoader export, saving ~500 bytes)

Third-party identity signals:
- Read _ga (GA Client ID), _fbc (Meta click ID), _fbp (Meta browser ID)
  cookies and include in page view properties when present

Bug fix:
- Register session_end listeners BEFORE queue.start() so that on page
  unload, session_end is enqueued before the queue's flushUnload fires
  (DOM listeners fire in registration order)

Bundle: 9.23 KB raw / 3.35 KB gzipped

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bkbooth bkbooth requested a review from a team as a code owner April 7, 2026 06:32
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 7, 2026

View your CI Pipeline Execution ↗ for commit 425e34e

Command Status Duration Result
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 2s View ↗
nx affected -t build,lint,test ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-08 01:02:21 UTC

Base automatically changed from SDK-50-pixel-core-consent to main April 8, 2026 00:43
@bkbooth bkbooth requested a review from a team as a code owner April 8, 2026 00:43
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bkbooth bkbooth added this pull request to the merge queue Apr 8, 2026
Merged via the queue into main with commit 7b06c8f Apr 8, 2026
8 checks passed
@bkbooth bkbooth deleted the SDK-50-pixel-bootstrap branch April 8, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants